package com.qf.controller.manager;

import com.qf.entitys.TbManagers;
import com.qf.service.TbManagersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/manager")
public class LoginController {

    @Resource
    private TbManagersService managersService;
    @GetMapping("/login")
    public String login(){
        return "manager/login";
    }

    @PostMapping("/login")
    public String login(String loginName, String loginPwd, HttpServletRequest request){
        TbManagers login = managersService.login(loginName, loginPwd);
        if(login!=null){
            request.getSession().setAttribute("login",login);
            return "manager/index";
        }else {
            request.setAttribute("loginerror","用户名密码错误");
            return "manager/login";
        }
    }
}
